﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SQLite;
using Com.Toook.AutoDownloadHtml.Util;

public partial class joke : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            InitRandomList();
            InitTopList();
            InitContentList();
        }
    }
    private void InitRandomList()
    {
        string sql = "select id, title from UncheckedJokeHaha365 limit 15 ";
        SQLiteConnection conn = SqliteHelper.GetConnection("SQLiteDatabase");
        SQLiteCommand cmd = new SQLiteCommand(sql, conn);
        SQLiteDataReader reader = null;
        try
        {
            conn.Open();
            reader = cmd.ExecuteReader();
            rptRandom.DataSource = reader;
            rptRandom.DataBind();
        }
        finally
        {
            SqliteHelper.CloseDbResource(conn, reader);
        }
    }
    private void InitTopList()
    {
        string sql = "select id, title from UncheckedJokeHaha365 limit 20, 15 ";
        SQLiteConnection conn = SqliteHelper.GetConnection("SQLiteDatabase");
        SQLiteCommand cmd = new SQLiteCommand(sql, conn);
        SQLiteDataReader reader = null;
        try
        {
            conn.Open();
            reader = cmd.ExecuteReader();
            rptTop.DataSource = reader;
            rptTop.DataBind();
        }
        finally
        {
            SqliteHelper.CloseDbResource(conn, reader);
        }
    }
    private void InitContentList()
    {
        string sql = "select id, title, content from UncheckedJokeHaha365 limit 40, 15 ";
        SQLiteConnection conn = SqliteHelper.GetConnection("SQLiteDatabase");
        SQLiteCommand cmd = new SQLiteCommand(sql, conn);
        SQLiteDataReader reader = null;
        try
        {
            conn.Open();
            reader = cmd.ExecuteReader();
            rptContent.DataSource = reader;
            rptContent.DataBind();
        }
        finally
        {
            SqliteHelper.CloseDbResource(conn, reader);
        }
    }
}
